﻿#region Using
/*
=============================================================================
Author:魏宝辉通过CodeSmithe生成
CreatedTime:2012-12-3
Description:Agency_Photo.aspx.cs页面代码
=============================================================================	
*/

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Text;
using FineUI;
using FTchina.SearchQuery;
using FTchina.Library;
using FTchina;
using PWMIS.DataMap.Entity;
#endregion
public partial class Agency_analyse_cs : BasePage
{


    string ReturnPage = "Agency_Photo.aspx";

    FTchina.SearchQuery.QueryModel qm = new FTchina.SearchQuery.QueryModel();//实例化搜索模型
    string WindowsPage = "Agency_Photoaction.aspx";//弹出窗口的页面地址

    protected void Page_Load(object sender, EventArgs e)
    {
        if (MasterHelper.BssAreaCode.Trim().Length == 0)
        {
            Response.Write("请联系管理员配置" + MasterHelper.ParentItemName + "关联AREA_CODE");
            Response.End();
        }
        if (!IsPostBack)
        {
            ShowSumCount();
            ShowState();
        }


    }

    protected void ShowSumCount()
    {
        PWMIS.DataProvider.Data.AdoHelper dydb = PWMIS.DataProvider.Adapter.MyDB.GetDBHelperByConnectionName("DYDB");
        string sumsql = @"select sum(t.count) from bssagencycountlist t ,bssagencylist cl 
where t.develop_depart_id=cl.depart_id
and cl.area_code in (" + MasterHelper.BssAreaCode + ")";
        string xx = dydb.ExecuteScalar(sumsql).ToString();
        txbcountAll.Text = xx;


        string Countsql = @"select count(*) as count from bssagencylist t where t.area_code in ("+MasterHelper.BssAreaCode+")";
        txblistcount.Text = dydb.ExecuteScalar(Countsql).ToString();

    }
    #region GRID显示放号情况


    protected void ShowState()
    {


        PWMIS.DataProvider.Data.AdoHelper dydb = PWMIS.DataProvider.Adapter.MyDB.GetDBHelperByConnectionName("DYDB");

        //string sql = "select * from bssagencycountlist t where t.depart_code='" + bsscode + "' ";
        //LogHelper.Debug(sql);
        //DataTable dt = dydb.ExecuteDataSet(sql).Tables[0];
        List<BSSAgencyCount> bclist = new List<BSSAgencyCount>();

        int year = DateTime.Now.Year;
        for (int i = year; i >= year - 2; i--)
        {
            BSSAgencyCount bc = new BSSAgencyCount();
            bc.Year = i.ToString();
            bc.M1 = getCountByBssCode(bc.Year + "01", dydb);
            bc.M2 = getCountByBssCode(bc.Year + "02", dydb);
            bc.M3 = getCountByBssCode(bc.Year + "03", dydb);
            bc.M4 = getCountByBssCode(bc.Year + "04", dydb);
            bc.M5 = getCountByBssCode(bc.Year + "05", dydb);
            bc.M6 = getCountByBssCode(bc.Year + "06", dydb);
            bc.M7 = getCountByBssCode(bc.Year + "07", dydb);
            bc.M8 = getCountByBssCode(bc.Year + "08", dydb);
            bc.M9 = getCountByBssCode(bc.Year + "09", dydb);
            bc.M10 = getCountByBssCode(bc.Year + "10", dydb);
            bc.M11 = getCountByBssCode(bc.Year + "11", dydb);
            bc.M12 = getCountByBssCode(bc.Year + "12", dydb);
            bc.Sum = getSumByBssCode(bc.Year, dydb);
            bclist.Add(bc);
        }
        Grid2.RecordCount = bclist.Count;
        Grid2.DataSource = bclist;
        Grid2.DataBind();

    }
    /// <summary>
    /// 获取代理商一月发展量
    /// </summary>
    /// <param name="bsscode"></param>
    /// <param name="YearMonth"></param>
    /// <returns></returns>
    private string getCountByBssCode(string YearMonth, PWMIS.DataProvider.Data.AdoHelper dydb)
    {
        string sql = @"select  nvl(sum(count),0) as count   from bssagencycountlist t ,bssagencylist cl 
where t.develop_depart_id=cl.depart_id
and cl.area_code in ("+MasterHelper.BssAreaCode+")"+
"and mon='" + YearMonth + "'";

        return dydb.ExecuteScalar(sql).ToString();
    }
    /// <summary>
    /// 获取代理商一年的发展量
    /// </summary>
    /// <param name="bsscode"></param>
    /// <param name="YearMonth"></param>
    /// <param name="dydb"></param>
    /// <returns></returns>
    private string getSumByBssCode(string YearMonth, PWMIS.DataProvider.Data.AdoHelper dydb)
    {
        string sql = @"select sum(t.count) as sum  from bssagencycountlist t ,bssagencylist cl 
where t.develop_depart_id=cl.depart_id
and cl.area_code in ("+MasterHelper.BssAreaCode+")"+
"and SUBSTR(mon,0,4)=" + YearMonth + "";

        return dydb.ExecuteScalar(sql).ToString();
    }
    class BSSAgencyCount
    {
        public string BssCode { get; set; }
        public string Year { get; set; }
        public string M1 { get; set; }
        public string M2 { get; set; }
        public string M3 { get; set; }
        public string M4 { get; set; }
        public string M5 { get; set; }
        public string M6 { get; set; }
        public string M7 { get; set; }
        public string M8 { get; set; }
        public string M9 { get; set; }
        public string M10 { get; set; }
        public string M11 { get; set; }
        public string M12 { get; set; }
        public string Sum { get; set; }
    }

    #endregion
}



